package uia.alumni.profile;

import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import uia.alumni.data.Role;
import uia.alumni.data.User;
import uia.alumni.web.Page;



/**
 * Make a page with a form for changing the logged in user's password.
 * @author Even Åby Larsen (even.larsen@uia.no)
 */
public class EditPassword  extends Page implements Constants {

    /** SERVLET_NAME is used for consistency checking of web.xml */
    public static final String SERVLET_NAME = "profile.editpassword";


    public EditPassword() {
        super(Role.member);
    }


    /**
     * Write a form for changing the password.
     * @param out
     * @param request
     */
    public void writeBody(PrintWriter out, HttpServletRequest request) {
        User user = getLoggedInUser(null, request);

        out.println("<h1>Changing password for "+user.getFullName()+"</h1>");
        this.printStartForm(out, SavePassword.SERVLET_NAME);
        out.println("<table>");
        printPasswordField(out, "Old password", OLDPASSWORD);
        printPasswordField(out, "New password", PASSWORD);
        printPasswordField(out, "Confirm new password", PASSWORD);
        out.println("<tr><td><input type=\"submit\" value=\"Change password\"/></td></tr>");
        out.println("</table>");
        out.println("</form>");
    }

    public final static long serialVersionUID = 1;

}
